#include "SLinkNode.cpp"

void reverse2(SLinkNode *&L) {
    SLinkNode *pre = NULL, *p = L->next, *next = p->next;
    while (next != NULL) {
        p->next = pre;
        pre = p;
        p = next;
        next = next->next;
    }
    p->next = pre;
    L->next = p;
}

void reverse(SLinkNode *&L) {
    SLinkNode *p = L->next, *q = p->next;
    p->next = NULL;
    while (q != NULL) {
        SLinkNode *r = q->next;
        q->next = p;
        p = q;
        q = r;
    }
    L->next = p;
}

int main() {
    int a[] = {1, 3, 7, 5, 4, 2};
    SLinkNode *L;
    CreateListF(L, a, 6);
    printf("单链表:");
    DispList(L);
    reverse(L);
    printf("逆置后:");
    DispList(L);
    return 0;
}